import json

from django.forms import model_to_dict
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from rest_framework.decorators import api_view
from chat_sys.models import Message
from enterprise_sys.models import Enterprise, Enterprise_Usr, Employee_info, Job, Resume
from utils.response_utils import *
from utils.session_utils import *
from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer
from utils.time_utils import *


def is_enterprise_not_exist(firm_id) -> bool:
    return Enterprise.objects.filter(id=firm_id).count() == 0


def is_enterprise_admin(usr_id, firm_id) -> bool:
    query = Enterprise_Usr.objects.filter(usr_id=usr_id, enterprise_id=firm_id)
    if query.count() == 0:
        return False
    return query[0].is_admin


def notice(code, receiver_id, msg):
    """
    根据给定的code值，向指定的receiver_id发送不同的通知消息msg。

    Args:
        code (int): 通知的类型代码，用于区分不同的通知模式。
                    可能的取值包括:
                    - 1: 发送认证通知
                    - 2: 发送点赞通知
                    - 3: 待扩展
        receiver_id (int): 接收通知的对象的唯一标识符。
        msg (str): 要发送的通知消息内容。

    Returns:
        None: 该函数不返回任何值，而是直接执行通知发送操作。

    """
    sender_id = 17
    msg_type = "default"
    if code == 3:
        msg_type = "notice"
    elif code == 1:
        msg_type = "add_employee"
    target_group_name = 'private_' + str(receiver_id)
    print(target_group_name)
    message_instance = Message.objects.create(sender_id=sender_id,
                                              receiver_id=receiver_id,
                                              msg_type=msg_type,
                                              content=msg,
                                              send_time=get_now_time())
    channel_layer = get_channel_layer()
    print(channel_layer)
    async_to_sync(channel_layer.group_send)(
        target_group_name,
        message_instance.parse_dict()
    )
    pass


def is_illegal_request(request, option):
    return request.method != option


def add_true(input_data=None):
    if input_data is None:
        return {'success': True}
    elif isinstance(input_data, dict):
        input_data['success'] = True
        return input_data
    else:
        raise ValueError("The provided input is not a dictionary.")


# Create your views here.
@csrf_exempt
def create_enterprise(request):
    if request.method != 'POST':
        return method_disallowed_response(request.method, 'POST')
    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')
    data = json.loads(request.body)
    name = data.get('enterpriseName')
    intro = data.get('enterpriseIntro')
    image_key = data.get('enterpriseImgKey')
    industry = data.get('enterpriseClass')
    if len(image_key) == 0:
        image_key = ''
    if len(name) > 30 or len(name) == 0:
        return build_response(errno=58983, msg='非法企业名')
    if len(Enterprise.objects.filter(name=name)) == 1:
        return build_response(errno=58983, msg='企业名已存在')
    if len(intro) > 1024:
        return build_response(errno=58983, msg='简介过长1024')
    if Enterprise_Usr.objects.filter(usr=user).count() != 0:
        return build_response(errno=58983, msg='当前用户已拥有企业!')
    enterprise = Enterprise.objects.create(
        name=name,
        intro=intro,
        industry=industry,
        image_key=image_key,
        creator_name=user.name
    )
    e_u = Enterprise_Usr.objects.create(usr=user, enterprise=enterprise, is_admin=True, is_agree=True)
    Employee_info.objects.create(e_u=e_u, name=user.name, position='管理员', contact_way=user.email)
    other_info = dict()
    other_info['success'] = True
    other_info['enterpriseId'] = enterprise.id
    return build_response(other_info=other_info, msg="创建成功", status=200)


@csrf_exempt
def get_info(request):
    if request.method != 'GET':
        return method_disallowed_response(request.method, 'GET')
    enterprise_id = request.GET.get('enterpriseId')
    if Enterprise.objects.filter(id=enterprise_id).count() == 0:
        return build_response(errno=58983, msg='企业不存在')
    enterprise = Enterprise.objects.get(id=enterprise_id)
    firm_info = enterprise.parse_dict()
    firm_info['success'] = True
    return build_response(other_info=firm_info, errno=1)


@csrf_exempt
@api_view(['PUT'])
def update_info(request):
    if request.method != 'PUT':
        return method_disallowed_response(request.method, 'PUT')
    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')
    firm_id = request.data.get('enterpriseId')
    if Enterprise.objects.filter(id=firm_id).count() == 0:
        return build_response(errno=58983, msg="企业不存在")
    firm = Enterprise.objects.get(id=firm_id)
    query = Enterprise_Usr.objects.filter(usr=user, enterprise=firm)
    if query.count() == 0:
        return build_response(errno=58983, msg="用户不属于该企业")
    else:
        firm_usr_instance = query[0]
        if not firm_usr_instance.is_admin:
            return build_response(errno=58983, msg="用户非该企业管理员!")
    name = request.data.get('enterpriseName')
    intro = request.data.get('enterpriseIntro')
    image_key = request.data.get('enterpriseImgKey')
    industry = request.data.get('enterpriseClass')
    contact_way = request.data.get('enterpriseContactWay')
    if len(name) != 0 and len(Enterprise.objects.filter(name=name)) == 1:
        if str(Enterprise.objects.get(name=name).id) != firm_id:
            return build_response(errno=58983, msg='企业名已存在')
    if len(intro) != 0 and len(intro) > 1024:
        return build_response(errno=58983, msg='简介过长1024')
    firm.name = name
    firm.intro = intro
    firm.image_key = image_key
    firm.industry = industry
    firm.contact_way = contact_way
    firm.save()
    other_info = {"success": True}
    return build_response(other_info=other_info, errno=1, msg='修改成功')


@csrf_exempt
def add_employee(request):
    if is_illegal_request(request, 'POST'):
        return method_disallowed_response(request, 'POST')
    if has_login(request):
        admin: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')

    data = json.loads(request.body)
    employee_id = data.get('usrId')
    firm_id = data.get('enterpriseId')
    print("add_employee_debug: add usrId:{}".format(employee_id))
    if User.objects.filter(id=employee_id).count() == 0:  # 不存在的用户
        return build_response(errno=58983, msg="该用户不存在")
    employee = User.objects.get(id=employee_id)

    if Enterprise.objects.filter(id=firm_id).count() == 0:
        return build_response(errno=58983, msg="该公司不存在")
    firm = Enterprise.objects.get(id=firm_id)

    query = Enterprise_Usr.objects.filter(usr=admin, enterprise=firm)
    if query.count() == 0:
        return build_response(errno=58983, msg="当前登录用户不属于该企业")
    else:
        firm_usr_instance = query[0]
        if not firm_usr_instance.is_admin:
            return build_response(errno=58983, msg="当前登录用户非该企业管理员!")

    if Enterprise_Usr.objects.filter(usr=employee, enterprise=firm).count() != 0:
        return build_response(errno=58983, msg='该用户已加入企业！')
    staff_name = data.get('staffName')
    staff_position = data.get('staffPosition')
    contact_way = data.get('contactWay')
    e_u = Enterprise_Usr.objects.create(usr=employee, enterprise=firm, is_admin=False, is_agree=False)
    Employee_info.objects.create(name=staff_name, position=staff_position, contact_way=contact_way, e_u_id=e_u.id)
    text = "您收到" + firm.name + "的邀请，请点击链接进行认证"
    msg = json.dumps({
        "enterpriseId": firm.id,
        "msg": text
    })
    notice(1, employee_id, msg)
    return build_response(other_info=add_true(), msg="添加员工成功")


@csrf_exempt
def get_verification(request):
    if is_illegal_request(request, 'GET'):
        return method_disallowed_response(request, 'GET')
    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')
    if Enterprise_Usr.objects.filter(usr=user, is_agree=False).count() == 0:
        return build_response(errno=58983, msg='无待认证的企业')

    enterprise_user_instance_list = Enterprise_Usr.objects.filter(usr=user, is_agree=False)
    info_list = []
    for enterprise_user_instance in enterprise_user_instance_list:
        firm = enterprise_user_instance.enterprise
        verify_id = enterprise_user_instance.id
        employee_info = Employee_info.objects.get(e_u_id=verify_id)
        enterprise_name = firm.name
        enterpriseId = firm.id
        position = employee_info.position
        info_list.append({
            "enterpriseName": enterprise_name,
            "verifyId": verify_id,
            "position": position,
            "enterpriseId": enterpriseId
        })
    return build_response(other_info={
        "success": True,
        "verificationList": info_list
    }, msg="获取成功")


@csrf_exempt
def enterprise_verify(request):
    if is_illegal_request(request, 'POST'):
        return method_disallowed_response(request, 'POST')
    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')

    verify_id = json.loads(request.body).get('verifyId')
    print(verify_id)
    query = Enterprise_Usr.objects.filter(id=verify_id)
    if query.count() == 0:
        return build_response(errno=58983, msg='无待认证的企业')
    else:
        enterprise_user = query[0]
    if enterprise_user.usr_id != user.id:
        return build_response(errno=58983, msg='用户错误')
    if enterprise_user.is_agree is True:
        return build_response(errno=58983, msg='该认证已通过！')
    query.update(is_agree=True)
    return build_response(other_info=add_true(), msg='认证成功')


@csrf_exempt
def delete_employee(request):
    if is_illegal_request(request, 'POST'):
        return method_disallowed_response(request, 'POST')

    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')
    data = json.loads(request.body)
    firm_id = data.get('enterpriseId')
    target_usr_id = data.get('targetUsrId')
    if is_enterprise_not_exist(firm_id):
        return build_response(errno=58983, msg='企业不存在')
    if not is_enterprise_admin(user.id, firm_id):
        return build_response(errno=58983, msg='当前用户非企业管理员')
    query = Enterprise_Usr.objects.filter(usr_id=target_usr_id, enterprise_id=firm_id)
    if query.count() == 0:
        return build_response(errno=58983, msg='用户不存在')
    employee_info = Employee_info.objects.filter(e_u_id=query[0].id)
    firm_name = Enterprise.objects.filter(id=firm_id).first().name
    msg = "您已被" + firm_name + "删除"
    notice(3, target_usr_id, msg)
    employee_info.delete()
    query[0].delete()
    return build_response(other_info=add_true(), msg='删除成功')


@csrf_exempt
def quit_enterprise(request):
    if is_illegal_request(request, 'POST'):
        return method_disallowed_response(request, 'POST')

    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(msg='用户未登录', other_info={"success": False})
    data = json.loads(request.body)
    firm_id = data.get('enterpriseId')
    if is_enterprise_not_exist(firm_id):
        return build_response(msg='企业不存在', other_info={"success": False})
    query = Enterprise_Usr.objects.filter(usr_id=user.id, enterprise_id=firm_id)
    if query.count() == 0:
        return build_response(msg='不属于该企业', other_info={"success": False})
    # notice()
    if query[0].is_admin:
        return build_response(msg='你是管理员', other_info={"success": False})
    delete_info = Employee_info.objects.filter(e_u_id=query[0].id)
    delete_info[0].delete()
    query[0].delete()
    return build_response(other_info=add_true(), msg='退出成功')


@csrf_exempt
def transform_enterprise(request):
    if is_illegal_request(request, 'POST'):
        return method_disallowed_response(request, 'POST')

    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(msg='用户未登录', other_info={"success": False})
    data = json.loads(request.body)
    firm_id = data.get('enterpriseId')
    target_userID = data.get('targetUserId')
    if is_enterprise_not_exist(firm_id):
        return build_response(msg='企业不存在', other_info={"success": False})
    query1 = Enterprise_Usr.objects.filter(usr_id=target_userID, enterprise_id=firm_id)
    query2 = Enterprise_Usr.objects.filter(usr_id=user.id, enterprise_id=firm_id)
    if query1.count() == 0:
        return build_response(msg='目标用户不属于该企业', other_info={"success": False})
    # notice()
    if not query2[0].is_admin:
        return build_response(msg='你不是管理员', other_info={"success": False})

    query1.update(is_admin=True)
    query2.update(is_admin=False)
    query1_info = Employee_info.objects.filter(e_u_id=query1[0].id)
    query1_info.update(position='管理员')
    query2_info = Employee_info.objects.filter(e_u_id=query2[0].id)
    query2_info.update(position='暂无职位')
    return build_response(other_info=add_true(), msg='转让成功')


@csrf_exempt
def delete_enterprise(request):
    if is_illegal_request(request, 'POST'):
        return method_disallowed_response(request, 'POST')

    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')

    data = json.loads(request.body)
    firm_id = data.get('enterpriseId')
    if is_enterprise_not_exist(firm_id):
        return build_response(msg='企业不存在', other_info={"success": False})

    query = Enterprise_Usr.objects.filter(usr_id=user.id, enterprise_id=firm_id)
    if query.count() == 0:
        return build_response(msg='你不属于该企业', other_info={"success": False})
    if not query[0].is_admin:
        return build_response(msg='你不是管理员', other_info={"success": False})
    enterprise_usr = Enterprise_Usr.objects.filter(enterprise_id=firm_id)
    enterprise_usr.delete()
    enterprise = Enterprise.objects.filter(id=firm_id)
    enterprise.delete()
    return build_response(other_info=add_true(), msg='删除成功')


@csrf_exempt
def get_employees(request):
    if request.method != 'GET':
        return method_disallowed_response(request.method, 'GET')
    firm_id = request.GET.get('enterpriseId')

    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')

    if Enterprise.objects.filter(id=firm_id).count() == 0:
        return build_response(errno=58983, msg='企业不存在')
    if not is_enterprise_admin(user.id, firm_id):
        return build_response(errno=58983, msg='非该企业管理员!')
    e_u_list = Enterprise_Usr.objects.filter(enterprise_id=firm_id)
    employee_list = []
    for e_u in e_u_list:
        print('query {}'.format(e_u.id))
        info = Employee_info.objects.get(e_u_id=e_u.id)
        item = info.parse_dict()
        item['id'] = e_u.usr.id
        item['is_admin'] = e_u.is_admin
        item['is_agree'] = e_u.is_agree
        employee_list.append(item)
    return_data = {"list": employee_list}
    return build_response(other_info=add_true(return_data), msg='获取员工列表成功')


@csrf_exempt
def add_job(request):
    if is_illegal_request(request, 'POST'):
        return method_disallowed_response(request, 'POST')
    if has_login(request):
        admin: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')

    data = json.loads(request.body)
    employee_id = data.get('usrId')
    firm_id = data.get('enterpriseId')
    print("add_employee_debug: add usrId:{}".format(employee_id))
    if User.objects.filter(id=employee_id).count() == 0:  # 不存在的用户
        return build_response(errno=58983, msg="该用户不存在")
    employee = User.objects.get(id=employee_id)

    if Enterprise.objects.filter(id=firm_id).count() == 0:
        return build_response(errno=58983, msg="该公司不存在")
    firm = Enterprise.objects.get(id=firm_id)

    name = data.get('name')
    job_count = data.get('job_count')
    salary = data.get('salary')
    requirement = data.get('requirement')
    place = data.get('place')
    education = data.get('education')

    if name == "" or name is None:
        return build_response(errno=58984, msg="职位名称不能为空")

    if job_count == "" or job_count is None:
        return build_response(errno=58984, msg="职位人数不能为空")
    try:
        job_count = int(job_count)
    except:
        return build_response(errno=58984, msg="职位人数必须为整数")
    if job_count <= 0:
        return build_response(errno=58984, msg="职位人数必须大于0")

    if salary:
        try:
            salary = float(salary)
            if salary <= 0:
                return build_response(errno=58984, msg="薪资必须大于0")
        except:
            return build_response(errno=58984, msg="薪资必须为数字")

    query = Enterprise_Usr.objects.filter(usr=admin, enterprise=firm)
    if query.count() == 0:
        return build_response(errno=58983, msg="当前登录用户不属于该企业")
    else:
        firm_usr_instance = query[0]
        print("firm_usr_instance: {}".format(firm_usr_instance))
        print(firm_usr_instance.id)
        print(firm_usr_instance)
        if not firm_usr_instance.is_admin:
            return build_response(errno=58983, msg="当前登录用户非该企业管理员!")
    job = Job.objects.create(user=query[0], enterprise=firm, name=name, job_count=job_count, salary=salary,
                             requirement=requirement, address=place, education=education)
    job.save()
    return build_response(other_info=add_true(), msg="添加招聘岗位成功")


@csrf_exempt
def get_jobs(request):
    if request.method != 'GET':
        return method_disallowed_response(request.method, 'GET')
    firm_id = request.GET.get('enterpriseId')
    print(firm_id)

    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')

    firm = Enterprise.objects.filter(id=firm_id)
    if firm.count() == 0:
        return build_response(errno=58983, msg='企业不存在')
    firm = firm[0]
    e_j_list = Job.objects.filter(enterprise=firm)
    job_list = []
    for e_j in e_j_list:
        print('query {}'.format(e_j.id))
        item = e_j.parse_dict()
        job_list.append(item)
    return_data = {"list": job_list}
    return build_response(other_info=add_true(return_data), msg='获取企业招聘岗位列表成功')


@csrf_exempt
def searchJobs(request):
    if request.method != 'GET':
        return method_disallowed_response(request.method, 'GET')
    job_name = request.GET.get('jobName')

    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')

    jobs = Job.objects.filter(name__icontains=job_name)
    if jobs.count() == 0:
        return build_response(msg='不存在该招聘信息', other_info={"success": False})
    data = []
    for job in jobs:
        job1 = model_to_dict(job)
        enterprise = Enterprise.objects.filter(id=job.enterprise_id)
        job1['enterprise_id'] = enterprise[0].id
        job1['enterprise_name'] = enterprise[0].name
        job1['enterprise_industry'] = enterprise[0].industry
        job1['enterprise_image_key'] = enterprise[0].image_key
        e_u = Enterprise_Usr.objects.filter(is_admin=1, enterprise_id=enterprise[0].id)
        job1['admin_id'] = e_u[0].usr_id
        admin = User.objects.filter(id=e_u[0].usr_id)
        job1['admin_name'] = admin[0].name
        data.append(job1)
    return build_response({
        "success": True,
        "datalist": data
    })


@csrf_exempt
def has_verification(request):
    if request.method != 'GET':
        return method_disallowed_response(request.method, 'GET')
    firm_id = request.GET.get('enterpriseId')
    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')
    if Enterprise.objects.filter(id=firm_id).count() == 0:
        return build_response(errno=58983, msg='企业不存在')
    query = Enterprise_Usr.objects.filter(usr_id=user.id, enterprise_id=firm_id)
    if query.count() == 0:
        return build_response(errno=58983, msg="未收到认证")
    return build_response(other_info={'isAccepted': query[0].is_agree, 'success': True}, msg="获取成功")


@csrf_exempt
def searchEnterprise(request):
    if request.method != 'GET':
        return method_disallowed_response(request.method, 'GET')
    if not has_login(request):
        return build_response(errno=2001, msg='用户未登录')
    enterpriseName = request.GET.get('enterpriseName')
    enterprises = Enterprise.objects.filter(name__icontains=enterpriseName)
    if enterprises.count() == 0:
        return build_response(msg='不存在该企业', other_info={"success": False})
    data = []
    for enterprise in enterprises:
        enterprise1 = model_to_dict(enterprise)
        e_u = Enterprise_Usr.objects.filter(is_admin=1, enterprise_id=enterprise.id)
        enterprise1['admin_id'] = e_u[0].usr_id
        data.append(enterprise1)

    return build_response({
        "success": True,
        "datalist": data
    })


@csrf_exempt
def postResume(request):
    if is_illegal_request(request, 'POST'):
        return method_disallowed_response(request, 'POST')
    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')
    data = json.loads(request.body)
    jobId = data.get('jobId')
    resume = Resume.objects.filter(job_id=jobId, user_id=user.id)
    if resume.count() != 0:
        return build_response(msg='您已应聘过该岗位', other_info={"success": False})
    Resume.objects.create(job_id=jobId, user_id=user.id)
    return build_response(other_info=add_true(), msg='应聘成功')


@csrf_exempt
def get_job_resume(request):
    if request.method != 'GET':
        return method_disallowed_response(request.method, 'GET')
    job_id = request.GET.get('jobId')
    print(job_id)

    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')

    job = Job.objects.filter(id=job_id)
    if job.count() == 0:
        return build_response(errno=58983, msg='岗位不存在')
    # if not is_enterprise_admin(user.id, firm_id):
    #     return build_response(errno=58983, msg='非该企业管理员!')
    job = job[0]
    resumes = Resume.objects.filter(job=job)
    resume_list = []
    for resume in resumes:
        print('query {}'.format(resume.id))
        item = resume.parse_dict()
        resume_list.append(item)
    return_data = {"list": resume_list}
    return build_response(other_info=add_true(return_data), msg='获取岗位简历列表成功')


@csrf_exempt
def mark_resume_accepted(request):
    if is_illegal_request(request, 'POST'):
        return method_disallowed_response(request, 'POST')
    if has_login(request):
        admin: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')

    data = json.loads(request.body)
    # 是否做权限校验？
    # employee_id = data.get('usrId')
    # firm_id = data.get('enterpriseId')
    # print("mark_resume_accepted_debug: add usrId:{}".format(employee_id))
    # if User.objects.filter(id=employee_id).count() == 0:  # 不存在的用户
    #     return build_response(errno=58983, msg="该用户不存在")
    # employee = User.objects.get(id=employee_id)
    #
    # if Enterprise.objects.filter(id=firm_id).count() == 0:
    #     return build_response(errno=58983, msg="该公司不存在")
    #
    # if not is_enterprise_admin(user.id, firm_id):
    #     return build_response(errno=58983, msg='非该企业管理员!')
    #
    # firm = Enterprise.objects.get(id=firm_id)

    resumeId = data.get('resumeId')

    if resumeId == "" or resumeId is None:
        return build_response(errno=58984, msg="简历ID不能为空")

    resume = Resume.objects.filter(id=resumeId)
    if resume.count() == 0:
        return build_response(errno=58983, msg="简历不存在")
    resume = resume[0]
    if resume.job.job_count <= 0:
        return build_response(errno=58983, msg="该岗位已满员")
    if resume.is_employ:
        return build_response(other_info={'success': True}, msg='简历已被接受')
    resume.is_employ = 1
    resume.save()
    # 更新岗位人数
    job = Job.objects.get(id=resume.job.id)
    job.job_count -= 1
    job.save()
    text = "您已被" + job.enterprise.name + "的" + job.title + "录用"
    msg = json.dumps({
        "enterpriseId": job.enterprise_id,
        "msg": text
    })
    notice(1, resume.user.id, msg)
    return build_response(other_info={'success': True}, msg='简历已被接受')


@csrf_exempt
def get_all_jobs(request):
    if request.method != 'GET':
        return method_disallowed_response(request.method, 'GET')

    if has_login(request):
        user: User = get_login_user(request)
    else:
        return build_response(errno=2001, msg='用户未登录')

    e_j_list = Job.objects.filter()
    job_list = []
    for e_j in e_j_list:
        print('query {}'.format(e_j.id))
        item = e_j.parse_dict()
        job_list.append(item)
    return_data = {"list": job_list}
    return build_response(other_info=add_true(return_data), msg='获取所有招聘岗位列表成功')


@csrf_exempt
def get_user_info_by_job_id(request):  # 懒得改名了凑合着吧
    if request.method != 'GET':
        return method_disallowed_response(request.method, 'GET')
    if not has_login(request):
        return build_response(errno=2001, msg='用户未登录')
    job_id = request.GET.get('jobId')
    job = Job.objects.filter(id=job_id)
    if job.count() == 0:
        return build_response(errno=58983, msg='不存在该岗位')
    data = job[0].parse_dict()
    return build_response(other_info=add_true(data), msg='获取成功')
